home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6447 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: function pointer in C++
  5. Date: 8 Feb 1996 14:10:54 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Message-ID: <4fd09e$hf3@dawn.mmm.com>
  8. References: <4f7rd5$6ha@transfer.stratus.com>
  9. Reply-To: kjhopps@mmm.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. davidm@ssi.stratus.com wrote:
  13. > I have read the FAQ but do not have it in front of me right now.  If
  14. > this question appears in it, my apologies.
  15.  
  16. > I am involved with a project to port a ton of C (ANSI and K&R) to
  17. > C++.  This is the first step in migration to an OO architecture.
  18.  
  19. > The previous programmer used a typedef for a pointer to a function
  20. > returning void that looks like this:
  21.  
  22. >    typedef void (*PFV)();
  23.  
  24. > It is used repeatedly through out the code to point to functions
  25. > that require arguements. The compiler complains about the mismatch
  26. > in the arguement list  Ex:
  27.  
  28. Yes.  Calling a function through a pointer to a different type of
  29. function results in undefined behavior.  But it is safe to cast
  30. to the proper function type and then call.
  31.  
  32. >    static void call_thru (int argc, char *argv[]);
  33.  
  34. >    PFV netx_entry_point = call_thru;
  35.  
  36. > (Note: they are not all just (int, char**)).
  37.  
  38. > I have gone through most of the code and removed the declarations
  39. > involving PFV and replaced with something like:
  40.  
  41. >    void (*netx_entry_point(int, char**) = call_thru;
  42.  
  43. > I would like to know if there is a more elegant or perhaps just plain
  44. > better way to handle this that is not obvious to me.
  45.  
  46. Correct syntax might be more elegant :-)
  47.  
  48. If you like the typedef, you might use that for the different types
  49. of functions:
  50.     typedef void (*ArgcArgvFunc)(int, char**);
  51.     ArgcArgvFunc netx_entry_point = call_thru;
  52. --
  53. Kevin J. Hopps                  e-mail: kjhopps@mmm.com
  54. 3M Company                      phone:  (612) 737-4643
  55. 3M Center, Bldg. 235-2D-57      fax:    (612) 737-2700
  56. St. Paul, MN 55144-1000         Opinions are my own.  I don't speak for 3M.
  57.     But 3M speaks for me -- I did not write the following line:
  58.  
  59. Opinions expressed herein are my own and may not represent those of 3M.
  60.